ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC1,commonC1,methyUniqC1),rev(n_K4me2_path)]
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# K4me3
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC1,commonC1,methyUniqC1),rev(n_K4me3_path)]
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# CGratio
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC1,commonC1,methyUniqC1),1])
plotMatrix[plotMatrix<CG_ratio_min] <- CG_ratio_min
plotMatrix[plotMatrix>CG_ratio_max] <- CG_ratio_max
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels="GCcontent",las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# CG class
ColorRamp <- colorRampPalette(c(cccol[1],cccol[2],cccol[3]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC1,commonC1,methyUniqC1),1])
CG_ratio_max <- 0.75
CG_ratio_min <- 0.5
plotMatrix[plotMatrix<CG_ratio_min] <- 0
plotMatrix[plotMatrix<CG_ratio_max & plotMatrix>CG_ratio_min] <- 0.5
plotMatrix[plotMatrix>CG_ratio_max] <- 1
ColorLevels <- seq(to=1,from=0, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels="GC class",las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
dev.off()
pdf("legend.pdf",width=1,height=6)
par(oma=c(0.5,0.5,0.5,0.5),mar=c(1,3,1,3))
layout(matrix(c(rep(1,6),rep(2,3),rep(3,2),rep(4,2),rep(5,1),rep(6,1)),nrow=15,ncol=1,byrow=T))
ColorRamp <- colorRampPalette(c("lightblue","red"), bias=1)(1000)
ColorLevels <- seq(to=exp_max,from=exp_min, length=1000)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(exp_min,round((exp_max-exp_min)/2,1),exp_max),labels=c(round(exp_min,2),round((exp_max-exp_min)/2,1),round(exp_max,1)),las=2)
ColorRamp <- colorRampPalette(c("white","black"), bias=1)(100)
ColorLevels <- seq(to=methy_max,from=methy_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(methy_min,round((methy_max-methy_min)/2,1),methy_max),labels=c(round(methy_min,2),round((methy_max-methy_min)/2,1),round(methy_max,1)),las=2)
ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(K4me2_min,round((K4me2_max-K4me2_min)/2,1),K4me2_max),labels=c(round(K4me2_min,2),round((K4me2_max-K4me2_min)/2,1),round(K4me2_max,1)),las=2)
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(K4me3_min,round((K4me3_max-K4me3_min)/2,1),K4me3_max),labels=c(round(K4me3_min,2),round((K4me3_max-K4me3_min)/2,1),round(K4me3_max,1)),las=2)
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(CG_ratio_min,CG_ratio_max),labels=c(round(CG_ratio_min,1),round(CG_ratio_max,1)),las=2)
ColorLevels <- c(0,0.5,1)
ColorRamp <- c(cccol[1],cccol[2],cccol[3])
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n")
axis(side=4,ColorLevels,labels=c("LCP","ICP","HCP"),las=2,cex.axis=0.5)
dev.off()
setwd("../../Fig6/")
###################################################################################################
####################################       read in data      ######################################
###################################################################################################
cccol <- c("#CE0013","#16557A","#C7A609","#87C232","#64C0AB","#A20C94","#15A08C","#8B7E75","#1E7CAF","#EA425F","#46489A","#E50033","#0F231F","#1187CD")
################### plot genes
K4me3C20 <- as.vector(read.table("../data/Fig6A/naiveK4me3PositiveGeneCluster20.txt")[,1])
methyC20 <- as.vector(read.table("../data/Fig6A/naiveMethylatedNegativeGeneCluster20.txt")[,1])
K4me3C17 <- as.vector(read.table("../data/Fig6A/naiveK4me3PositiveGeneCluster17.txt")[,1])
methyC17 <- as.vector(read.table("../data/Fig6A/naiveMethylatedNegativeGeneCluster17.txt")[,1])
K4me3C9 <- as.vector(read.table("../data/Fig6A/naiveK4me3PositiveGeneCluster9.txt")[,1])
methyC9 <- as.vector(read.table("../data/Fig6A/naiveMethylatedNegativeGeneCluster9.txt")[,1])
K4me3C1 <- as.vector(read.table("../data/Fig6A/naiveK4me3PositiveGeneCluster10.txt")[,1])
methyC1 <- as.vector(read.table("../data/Fig6A/naiveMethylatedNegativeGeneCluster10.txt")[,1])
C20 <- union(K4me3C20,methyC20)
K4me3UniqC20 <- setdiff(K4me3C20,methyC20)
methyUniqC20 <- setdiff(methyC20,K4me3C20)
commonC20 <- intersect(K4me3C20,methyC20)
C17 <- union(K4me3C17,methyC17)
K4me3UniqC17 <- setdiff(K4me3C17,methyC17)
methyUniqC17 <- setdiff(methyC17,K4me3C17)
commonC17 <- intersect(K4me3C17,methyC17)
C9 <- union(K4me3C9,methyC9)
K4me3UniqC9 <- setdiff(K4me3C9,methyC9)
methyUniqC9 <- setdiff(methyC9,K4me3C9)
commonC9 <- intersect(K4me3C9,methyC9)
C1 <- union(K4me3C1,methyC1)
K4me3UniqC1 <- setdiff(K4me3C1,methyC1)
methyUniqC1 <- setdiff(methyC1,K4me3C1)
commonC1 <- intersect(K4me3C1,methyC1)
################### plot data
## 2nd naive gene expression
logfpkm2nd <- read.table("../data/2nd.reprogramming.lg2.all.fpkm.txt",header=T,row.names=1)
n_path <- c("hiF_r1","hiF_r2","he0_r1","he0_r2","he2_r1","he2_r2","he6_r1","he6_r2","n8_r1","n8_r2","n12_r1","n12_r2","n14_r1","n14_r2","n20_r1","n20_r2","n24m_r1","n24m_r2","n24p_r1","n24p_r2","niPS_r1","niPS_r2")
nData_tmp <- logfpkm2nd[,n_path]
nfpkm2nd <- 2**nData_tmp - 1
n_time_point <- c("hiF","he0","he2","he6","n8","n12","n14","n20","n24pdox","n24mdox","niPS")
n_label <- c("hiF-T","0d","2d","6d","8d","12d","14d","20d","24d+dox","24d-dox","niPSC-T")
nData2ndfpkm <- cbind(apply(nfpkm2nd[,1:2],1,mean),apply(nfpkm2nd[,3:4],1,mean),apply(nfpkm2nd[,5:6],1,mean),apply(nfpkm2nd[,7:8],1,mean),apply(nfpkm2nd[,9:10],1,mean),apply(nfpkm2nd[,11:12],1,mean),apply(nfpkm2nd[,13:14],1,mean),apply(nfpkm2nd[,15:16],1,mean),apply(nfpkm2nd[,17:18],1,mean),apply(nfpkm2nd[,19:20],1,mean),apply(nfpkm2nd[,21:22],1,mean))
colnames(nData2ndfpkm) <- n_time_point
rownames(nData2ndfpkm) <- rownames(nfpkm2nd)
nData <- log2(nData2ndfpkm[,]+1)
n_deg <- read.table("../Fig2/Gfold/cutoff.0.58/naive.2nd.deg")[,1]
n_deg <- intersect(n_deg,rownames(nData))
nData <- nData[n_deg,]
## 2nd naive DNA methylation ratio on promoter
methyratio_promoter <- read.table("../data/2nd_average_methratio_on_promoter.txt",header=T,row.names=1)
hiFT <- methyratio_promoter[,"hiFT"]
he6 <- methyratio_promoter[,"he6"]
n12 <- apply(methyratio_promoter[,c("n12","n12_r2")],1,mean,na.rm=TRUE)
n20 <- methyratio_promoter[,"n20"]
n24 <- methyratio_promoter[,"n24"]
niPS <- methyratio_promoter[,"niPS"]
methyratio_promoter <- cbind(hiFT,he6,n12,n20,n24,niPS)
methy_n_path <- c("hiFT","he6","n12","n20","n24","niPS")
methy_n_label <- c("hiF-T","6d","12d","20d","24d+dox","niPSC-T")
## 2nd naive HM on promoter
hm_promoter <- read.table("../data/HM_gene_promoter_uniq_all.txt",header=T,row.names=1)
hm_n_path <- c("hiF","he6","n24","niPS")
hm_p_path <- c("hiF","he6","p24","piPS")
n_K4me2_path <- c("hiF_K4me2","he6_K4me2","n24_K4me2","niPS_K4me2")
p_K4me2_path <- c("hiF_K4me2","he6_K4me2","p24_K4me2","piPS_K4me2")
n_K4me3_path <- c("hiF_K4me3","he6_K4me3","n24_K4me3","niPS_K4me3")
p_K4me3_path <- c("hiF_K4me3","he6_K4me3","p24_K4me3","piPS_K4me3")
hm_n_label <- c("hiF-T","6d","24d+dox","niPSC-T")
################### sequence feature
cg_ratio <- read.table("../data/hg19.promoter.CG.density.uniq.txt",row.names=1)
###################################################################################################
####################################         heatmap         ######################################
###################################################################################################
all_exp <- c(as.matrix(nData[c(C20,C9,C17,C1),]))
exp_max <- quantile(all_exp,0.99)
exp_min <- quantile(all_exp,0.01)
methy_max <- 1
methy_min <- 0
all_K4me2 <- c(as.matrix(hm_promoter[c(C20,C9,C17,C1),n_K4me2_path]))
K4me2_max <- quantile(na.omit(all_K4me2),0.99)
K4me2_min <- quantile(na.omit(all_K4me2),0.01)
all_K4me3 <- c(as.matrix(hm_promoter[c(C20,C9,C17,C1),n_K4me3_path]))
K4me3_max <- quantile(na.omit(all_K4me3),0.99)
K4me3_min <- quantile(na.omit(all_K4me3),0.01)
CG_ratio_max <- quantile(na.omit(cg_ratio[,1]),0.99)
CG_ratio_min <- quantile(na.omit(cg_ratio[,1]),0.01)
pdf("C20.pdf",width=length(C20)/20+1,height=6)
par(oma=c(0.5,0.5,0.5,0.5),mar=c(1,4,1,2))
layout(matrix(c(rep(1,6),rep(2,3),rep(3,2),rep(4,2),rep(5,1),rep(6,1)),nrow=15,ncol=1,byrow=T))
# gene expression
ColorRamp <- colorRampPalette(c("lightblue","red"), bias=1)(1000)
plotMatrix <- nData[c(K4me3UniqC20,commonC20,methyUniqC20),rev(n_time_point)]
plotMatrix[plotMatrix<exp_min] <- exp_min
plotMatrix[plotMatrix>exp_max] <- exp_max
ColorLevels <- seq(to=exp_max,from=exp_min, length=1000)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), plotMatrix, axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(n_label),las=2)
abline(v=length(K4me3UniqC20)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC20)+length(commonC20)+0.5,lty=1,lwd=3)
# DNA methylation
ColorRamp <- colorRampPalette(c("white","black"), bias=1)(100)
plotMatrix <- methyratio_promoter[c(K4me3UniqC20,commonC20,methyUniqC20),rev(methy_n_path)]
# plotMatrix[is.na(plotMatrix)] <- 0
ColorLevels <- seq(to=methy_max,from=methy_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(methy_n_label),las=2)
abline(v=length(K4me3UniqC20)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC20)+length(commonC20)+0.5,lty=1,lwd=3)
# K4me2
ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC20,commonC20,methyUniqC20),rev(n_K4me2_path)]
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC20)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC20)+length(commonC20)+0.5,lty=1,lwd=3)
# K4me3
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC20,commonC20,methyUniqC20),rev(n_K4me3_path)]
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC20)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC20)+length(commonC20)+0.5,lty=1,lwd=3)
# CGratio
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC20,commonC20,methyUniqC20),1])
plotMatrix[plotMatrix<CG_ratio_min] <- CG_ratio_min
plotMatrix[plotMatrix>CG_ratio_max] <- CG_ratio_max
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels="GCcontent",las=2)
abline(v=length(K4me3UniqC20)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC20)+length(commonC20)+0.5,lty=1,lwd=3)
# CG class
ColorRamp <- colorRampPalette(c(cccol[1],cccol[2],cccol[3]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC9,commonC9,methyUniqC9),1])
CG_ratio_max <- 0.75
CG_ratio_min <- 0.5
plotMatrix[plotMatrix<=CG_ratio_min] <- 1
plotMatrix[plotMatrix<CG_ratio_max & plotMatrix>CG_ratio_min] <- 0.5
plotMatrix[plotMatrix>=CG_ratio_max] <- 0
ColorLevels <- seq(to=1,from=0, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels="GC class",las=2)
abline(v=length(K4me3UniqC20)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC20)+length(commonC9)+0.5,lty=1,lwd=3)
dev.off()
pdf("C17.pdf",width=length(C17)/20+1,height=6)
par(oma=c(0.5,0.5,0.5,0.5),mar=c(1,4,1,2))
layout(matrix(c(rep(1,6),rep(2,3),rep(3,2),rep(4,2),rep(5,1),rep(6,1)),nrow=15,ncol=1,byrow=T))
# gene expression
ColorRamp <- colorRampPalette(c("lightblue","red"), bias=1)(1000)
plotMatrix <- nData[c(K4me3UniqC17,commonC17,methyUniqC17),rev(n_time_point)]
plotMatrix[plotMatrix<exp_min] <- exp_min
plotMatrix[plotMatrix>exp_max] <- exp_max
ColorLevels <- seq(to=exp_max,from=exp_min, length=1000)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), plotMatrix, axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(n_label),las=2)
abline(v=length(K4me3UniqC17)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC17)+length(commonC17)+0.5,lty=1,lwd=3)
# DNA methylation
ColorRamp <- colorRampPalette(c("white","black"), bias=1)(100)
plotMatrix <- methyratio_promoter[c(K4me3UniqC17,commonC17,methyUniqC17),rev(methy_n_path)]
# plotMatrix[is.na(plotMatrix)] <- 0
ColorLevels <- seq(to=methy_max,from=methy_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(methy_n_label),las=2)
abline(v=length(K4me3UniqC17)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC17)+length(commonC17)+0.5,lty=1,lwd=3)
# K4me2
ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC17,commonC17,methyUniqC17),rev(n_K4me2_path)]
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC17)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC17)+length(commonC17)+0.5,lty=1,lwd=3)
# K4me3
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC17,commonC17,methyUniqC17),rev(n_K4me3_path)]
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC17)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC17)+length(commonC17)+0.5,lty=1,lwd=3)
# CGratio
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC17,commonC17,methyUniqC17),1])
plotMatrix[plotMatrix<CG_ratio_min] <- CG_ratio_min
plotMatrix[plotMatrix>CG_ratio_max] <- CG_ratio_max
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels="GCcontent",las=2)
abline(v=length(K4me3UniqC17)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC17)+length(commonC17)+0.5,lty=1,lwd=3)
# CG class
ColorRamp <- colorRampPalette(c(cccol[1],cccol[2],cccol[3]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC9,commonC9,methyUniqC9),1])
CG_ratio_max <- 0.75
CG_ratio_min <- 0.5
plotMatrix[plotMatrix<CG_ratio_min] <- 0
plotMatrix[plotMatrix<CG_ratio_max & plotMatrix>CG_ratio_min] <- 0.5
plotMatrix[plotMatrix>CG_ratio_max] <- 1
ColorLevels <- seq(to=1,from=0, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels="GC class",las=2)
abline(v=length(K4me3UniqC17)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC17)+length(commonC9)+0.5,lty=1,lwd=3)
dev.off()
pdf("C9.pdf",width=length(C9)/20+1,height=6)
par(oma=c(0.5,0.5,0.5,0.5),mar=c(1,4,1,2))
layout(matrix(c(rep(1,6),rep(2,3),rep(3,2),rep(4,2),rep(5,1),rep(6,1)),nrow=15,ncol=1,byrow=T))
# gene expression
ColorRamp <- colorRampPalette(c("lightblue","red"), bias=1)(1000)
plotMatrix <- nData[c(K4me3UniqC9,commonC9,methyUniqC9),rev(n_time_point)]
plotMatrix[plotMatrix<exp_min] <- exp_min
plotMatrix[plotMatrix>exp_max] <- exp_max
ColorLevels <- seq(to=exp_max,from=exp_min, length=1000)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), plotMatrix, axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(n_label),las=2)
abline(v=length(K4me3UniqC9)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC9)+length(commonC9)+0.5,lty=1,lwd=3)
# DNA methylation
ColorRamp <- colorRampPalette(c("white","black"), bias=1)(100)
plotMatrix <- methyratio_promoter[c(K4me3UniqC9,commonC9,methyUniqC9),rev(methy_n_path)]
# plotMatrix[is.na(plotMatrix)] <- 0
ColorLevels <- seq(to=methy_max,from=methy_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(methy_n_label),las=2)
abline(v=length(K4me3UniqC9)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC9)+length(commonC9)+0.5,lty=1,lwd=3)
# K4me2
ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC9,commonC9,methyUniqC9),rev(n_K4me2_path)]
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC9)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC9)+length(commonC9)+0.5,lty=1,lwd=3)
# K4me3
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC9,commonC9,methyUniqC9),rev(n_K4me3_path)]
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
# axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC9)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC9)+length(commonC9)+0.5,lty=1,lwd=3)
# CGratio
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC9,commonC9,methyUniqC9),1])
plotMatrix[plotMatrix<CG_ratio_min] <- CG_ratio_min
plotMatrix[plotMatrix>CG_ratio_max] <- CG_ratio_max
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
abline(v=length(K4me3UniqC9)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC9)+length(commonC9)+0.5,lty=1,lwd=3)
# CG class
ColorRamp <- colorRampPalette(c(cccol[1],cccol[2],cccol[3]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC9,commonC9,methyUniqC9),1])
CG_ratio_max <- 0.75
CG_ratio_min <- 0.5
plotMatrix[plotMatrix<CG_ratio_min] <- 0
plotMatrix[plotMatrix<CG_ratio_max & plotMatrix>CG_ratio_min] <- 0.5
plotMatrix[plotMatrix>CG_ratio_max] <- 1
ColorLevels <- seq(to=1,from=0, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
abline(v=length(K4me3UniqC9)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC9)+length(commonC9)+0.5,lty=1,lwd=3)
dev.off()
pdf("C1.pdf",width=length(C1)/20+1.2,height=6)
par(oma=c(0.5,0.5,0.5,0.5),mar=c(1,6,1,2))
layout(matrix(c(rep(1,6),rep(2,3),rep(3,2),rep(4,2),rep(5,1),rep(6,1)),nrow=15,ncol=1,byrow=T))
# gene expression
ColorRamp <- colorRampPalette(c("lightblue","red"), bias=1)(1000)
plotMatrix <- nData[c(K4me3UniqC1,commonC1,methyUniqC1),rev(n_time_point)]
plotMatrix[plotMatrix<exp_min] <- exp_min
plotMatrix[plotMatrix>exp_max] <- exp_max
ColorLevels <- seq(to=exp_max,from=exp_min, length=1000)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), plotMatrix, axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels=rev(n_label),las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# DNA methylation
ColorRamp <- colorRampPalette(c("white","black"), bias=1)(100)
plotMatrix <- methyratio_promoter[c(K4me3UniqC1,commonC1,methyUniqC1),rev(methy_n_path)]
# plotMatrix[is.na(plotMatrix)] <- 0
ColorLevels <- seq(to=methy_max,from=methy_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels=rev(methy_n_label),las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# K4me2
ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC1,commonC1,methyUniqC1),rev(n_K4me2_path)]
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# K4me3
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
plotMatrix <- hm_promoter[c(K4me3UniqC1,commonC1,methyUniqC1),rev(n_K4me3_path)]
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels=rev(hm_n_label),las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# CGratio
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC1,commonC1,methyUniqC1),1])
plotMatrix[plotMatrix<CG_ratio_min] <- CG_ratio_min
plotMatrix[plotMatrix>CG_ratio_max] <- CG_ratio_max
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels="GCcontent",las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
# CG class
ColorRamp <- colorRampPalette(c(cccol[1],cccol[2],cccol[3]), bias=1)(100)
plotMatrix <- as.matrix(cg_ratio[c(K4me3UniqC1,commonC1,methyUniqC1),1])
CG_ratio_max <- 0.75
CG_ratio_min <- 0.5
plotMatrix[plotMatrix<CG_ratio_min] <- 0
plotMatrix[plotMatrix<CG_ratio_max & plotMatrix>CG_ratio_min] <- 0.5
plotMatrix[plotMatrix>CG_ratio_max] <- 1
ColorLevels <- seq(to=1,from=0, length=100)
image(1:nrow(plotMatrix), 1:ncol(plotMatrix), as.matrix(plotMatrix), axes=F, col=ColorRamp, xlab="",ylab="")
axis(side=2,1:ncol(plotMatrix),labels="GC class",las=2)
abline(v=length(K4me3UniqC1)+0.5,lty=1,lwd=3)
abline(v=length(K4me3UniqC1)+length(commonC1)+0.5,lty=1,lwd=3)
dev.off()
pdf("legend.pdf",width=1,height=6)
par(oma=c(0.5,0.5,0.5,0.5),mar=c(1,3,1,3))
layout(matrix(c(rep(1,6),rep(2,3),rep(3,2),rep(4,2),rep(5,1),rep(6,1)),nrow=15,ncol=1,byrow=T))
ColorRamp <- colorRampPalette(c("lightblue","red"), bias=1)(1000)
ColorLevels <- seq(to=exp_max,from=exp_min, length=1000)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(exp_min,round((exp_max-exp_min)/2,1),exp_max),labels=c(round(exp_min,2),round((exp_max-exp_min)/2,1),round(exp_max,1)),las=2)
ColorRamp <- colorRampPalette(c("white","black"), bias=1)(100)
ColorLevels <- seq(to=methy_max,from=methy_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(methy_min,round((methy_max-methy_min)/2,1),methy_max),labels=c(round(methy_min,2),round((methy_max-methy_min)/2,1),round(methy_max,1)),las=2)
ColorRamp <- colorRampPalette(c("white",cccol[1]), bias=1)(100)
ColorLevels <- seq(to=K4me2_max,from=K4me2_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(K4me2_min,round((K4me2_max-K4me2_min)/2,1),K4me2_max),labels=c(round(K4me2_min,2),round((K4me2_max-K4me2_min)/2,1),round(K4me2_max,1)),las=2)
ColorRamp <- colorRampPalette(c("white",cccol[2]), bias=1)(100)
ColorLevels <- seq(to=K4me3_max,from=K4me3_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(K4me3_min,round((K4me3_max-K4me3_min)/2,1),K4me3_max),labels=c(round(K4me3_min,2),round((K4me3_max-K4me3_min)/2,1),round(K4me3_max,1)),las=2)
ColorRamp <- colorRampPalette(c(cccol[6],"white",cccol[5]), bias=1)(100)
ColorLevels <- seq(to=CG_ratio_max,from=CG_ratio_min, length=100)
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n",useRaster=T)
axis(side=4,c(CG_ratio_min,CG_ratio_max),labels=c(round(CG_ratio_min,1),round(CG_ratio_max,1)),las=2)
ColorLevels <- c(0,0.5,1)
ColorRamp <- c(cccol[1],cccol[2],cccol[3])
image(1,ColorLevels,t(matrix(data=ColorLevels, nrow=length(ColorLevels),ncol=1)),col=t(ColorRamp), xlab="",ylab="",cex.axis=2,xaxt="n",yaxt="n")
axis(side=4,ColorLevels,labels=c("LCP","ICP","HCP"),las=2,cex.axis=0.5)
dev.off()
setwd("../data/Fig6A/")
naive_cutoff <- -0.8
nm_gene <- names(which(na.omit(n_cor < naive_cutoff)))
other_gene <- setdiff(names(na.omit(n_cor_pvalue)),nm_gene)
pdf("naive.methylation.expression.correlation.pdf",width=5,height=4)
# plot(na.omit(n_cor)[other_gene],-log10(na.omit(n_cor_pvalue)[other_gene]),pch='.',xlab="correlation",ylab="-log10(p-value)",ylim=c(0,5))
# points(na.omit(n_cor)[nm_gene],-log10(na.omit(n_cor_pvalue)[nm_gene]),pch='.',col=cccol[1])
smoothScatter(na.omit(n_cor),-log10(na.omit(n_cor_pvalue)),pch='.',xlab="correlation",ylab="-log10(p-value)",ylim=c(0,5))
points(na.omit(n_cor)[other_gene],-log10(na.omit(n_cor_pvalue)[other_gene]),pch='.')
points(na.omit(n_cor)[nm_gene],-log10(na.omit(n_cor_pvalue)[nm_gene]),pch='.',col=cccol[1])
abline(h=-log10(pvalue_cutoff),lty=2,col=cccol[1])
abline(v=0,lty=2)
# plot(na.omit(n_cor),na.omit(n_cor_pvalue),pch='.',xlab="correlation",ylab="p-value")
dev.off()
nm_negative_gene <- names(which((na.omit(n_cor_pvalue) < pvalue_cutoff)&na.omit(n_cor)<0))
nm_positive_gene <- names(which((na.omit(n_cor_pvalue) < pvalue_cutoff)&na.omit(n_cor)>0))
write.table(cbind(nm_negative_gene),file="naiveMethylationNegativeGenes.txt",col.names=F,row.names=F,quote=F)
write.table(cbind(nm_positive_gene),file="naiveMethylationPositiveGenes.txt",col.names=F,row.names=F,quote=F)
nm_cluster_gene <- intersect(nm_negative_gene,n_deg)
total_number <- nrow(nData)
pval <- c()
ratio <- c()
cluster_ratio <- c()
number <- c()
for (each_cluster in seq(k)){
GroupB <- names(which(km$cluster==each_cluster))
common_number <- length(intersect(nm_cluster_gene,GroupB))
a_number <- length(nm_cluster_gene)
b_number <- length(GroupB)
number <- c(number,common_number)
pval <- c(pval,1-phyper(common_number-1, a_number, total_number-a_number, b_number))
print(c(common_number-1, a_number, total_number-a_number, b_number))
ratio <- c(ratio,common_number/a_number)
cluster_ratio <- c(cluster_ratio,common_number/b_number)
write.table(cbind(intersect(nm_cluster_gene,GroupB)),file=paste("naiveMethylatedNegativeGeneCluster",each_cluster,".txt",sep=""),col.names=F,row.names=F,quote=F)
}
pdf("naive.methylated.negative.gene.pvalue.pdf",width=7,height=4)
barplot(-log10(pval+10e-9),names.arg=seq(20),col=replace(rep("black",17),c(1,11),cccol[1]),border=NA,ylab="-log10(p-value)")
abline(h=2,lty=2)
dev.off()
nm_cluster_gene <- intersect(nm_positive_gene,n_deg)
total_number <- nrow(nData)
pval <- c()
ratio <- c()
cluster_ratio <- c()
number <- c()
for (each_cluster in seq(k)){
GroupB <- names(which(km$cluster==each_cluster))
common_number <- length(intersect(nm_cluster_gene,GroupB))
a_number <- length(nm_cluster_gene)
b_number <- length(GroupB)
number <- c(number,common_number)
pval <- c(pval,1-phyper(common_number-1, a_number, total_number-a_number, b_number))
ratio <- c(ratio,common_number/a_number)
cluster_ratio <- c(cluster_ratio,common_number/b_number)
write.table(cbind(intersect(nm_cluster_gene,GroupB)),file=paste("naiveMethylatedPositiveGeneCluster",each_cluster,".txt",sep=""),col.names=F,row.names=F,quote=F)
}
pdf("naive.methylated.positive.gene.pvalue.pdf",width=7,height=4)
barplot(-log10(pval+10e-9),names.arg=seq(20),col=replace(rep("black",17),c(4,10,14,15),cccol[1]),border=NA,ylab="-log10(p-value)")
abline(h=2,lty=2)
dev.off()
naive_cutoff <- -0.8
nm_gene <- names(which(na.omit(n_cor < naive_cutoff)))
other_gene <- setdiff(names(na.omit(n_cor_pvalue)),nm_gene)
nm_negative_gene <- nm_gene
write.table(cbind(nm_gene),file="naiveMethylationNegativeGenes.txt",col.names=F,row.names=F,quote=F)
nm_cluster_gene <- intersect(nm_negative_gene,n_deg)
total_number <- nrow(nData)
pval <- c()
ratio <- c()
cluster_ratio <- c()
number <- c()
for (each_cluster in seq(k)){
GroupB <- names(which(km$cluster==each_cluster))
common_number <- length(intersect(nm_cluster_gene,GroupB))
a_number <- length(nm_cluster_gene)
b_number <- length(GroupB)
number <- c(number,common_number)
pval <- c(pval,1-phyper(common_number-1, a_number, total_number-a_number, b_number))
print(c(common_number-1, a_number, total_number-a_number, b_number))
ratio <- c(ratio,common_number/a_number)
cluster_ratio <- c(cluster_ratio,common_number/b_number)
write.table(cbind(intersect(nm_cluster_gene,GroupB)),file=paste("naiveMethylatedNegativeGeneCluster",each_cluster,".txt",sep=""),col.names=F,row.names=F,quote=F)
}
pdf("naive.methylated.negative.gene.pvalue.pdf",width=7,height=4)
barplot(-log10(pval+10e-9),names.arg=seq(20),col=replace(rep("black",17),c(1,11),cccol[1]),border=NA,ylab="-log10(p-value)")
abline(h=2,lty=2)
dev.off()
